<template>
  <div>
    <el-button style="float: right; padding: 3px 0" type="text" @click="getEqs">刷新</el-button>
    <el-table :data="info.eqs.eq" @row-dblclick="toEq">
      <el-table-column property="name" label="板卡名称" width="300" sortable></el-table-column>
      <el-table-column property="me" label="所属机框"></el-table-column>
      <el-table-column property="slot" label="所属槽位" width="100"></el-table-column>
      <el-table-column width="150" property="plug-state" label="在位状态">
        <template slot-scope="scope">
          <el-tag
              :type="scope.row['plug-state'] ? 'primary' : 'danger'"
              disable-transitions>{{ scope.row['plug-state'] ? '是' : '否' }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column width="150" property="eq-type" label="板卡类型"></el-table-column>
      <el-table-column width="150" property="eq-sn" label="SN码"></el-table-column>
      <el-table-column width="auto" property="software-version" label="软件版本"></el-table-column>
      <el-table-column width="auto" property="hardware-version" label="硬件版本"></el-table-column>
      <el-table-column width="150" property="eq-state" label="运行状态"></el-table-column>
    </el-table>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: "EqList",
  data() {
    return {
      nodeName: '',
      info: {
        eqs: {
          "eq": [
            {
              "name": "槽道-1 OTN2X8",
              "plug-state": true,
              me: 'otna',
              slot: '1',
              "software-version": "v1.0.8  -2020/8/7 16:50:48",
              "hardware-version": "pcb_ver:1 board_type:none",
              'eq-type': 'Power',
              'eq-sn': 'cd12-322344',
              "ptp": [
                "PTP=/shelf=1/slot=1/subslot=1/port=9",
                "PTP=/shelf=1/slot=1/subslot=1/port=8",
                "PTP=/shelf=1/slot=1/subslot=1/port=10",
                "PTP=/shelf=1/slot=1/subslot=1/port=7"
              ],
              "eq-state": "初始化中···"
            },
            {
              "name": "槽道-2 OTN2X8",
              "plug-state": false,
              me: 'otna',
              slot: '1',
              "software-version": "v1.0.8  -2020/8/7 16:50:48",
              "hardware-version": "pcb_ver:1 board_type:none",
              'eq-type': 'Service',
              'eq-sn': 'cd12-fg-44',
              "ptp": [
                "PTP=/shelf=1/slot=1/subslot=1/port=9",
                "PTP=/shelf=1/slot=1/subslot=1/port=8",
                "PTP=/shelf=1/slot=1/subslot=1/port=10",
                "PTP=/shelf=1/slot=1/subslot=1/port=7"
              ],
              "eq-state": "正常工作"
            },
            {
              "name": "槽道-3 OTN2X8",
              "plug-state": false,
              me: 'otna',
              slot: '1',
              "software-version": "v1.0.8  -2020/8/7 16:50:48",
              "hardware-version": "pcb_ver:1 board_type:none",
              'eq-type': 'Clock',
              'eq-sn': 'fb12-3223-66',
              "ptp": [
                "PTP=/shelf=1/slot=1/subslot=1/port=9",
                "PTP=/shelf=1/slot=1/subslot=1/port=8",
                "PTP=/shelf=1/slot=1/subslot=1/port=10",
                "PTP=/shelf=1/slot=1/subslot=1/port=7"
              ],
              "eq-state": "故障"
            }
          ]
        },
      }

    }
  },
  methods: {
    toEq(row, column, event){
      this.$router.push({
        name:'EQ',
        params:{
          name:row.name
        }
      })
      console.log(row, column, event);
      console.log('当前行数据',row);
      console.log('当前行DOM',column);
      console.log('当前行事件',event);

    },
    getEqs() {
      if (this.nodeName !== '') {
        axios.get("/node/otndev"+"/eqs").then(
            response => {
              console.log("请求成功", response.data);
              this.$message.success("获取设备信息成功");
              this.info = response.data;
            },
            error => {
              console.log("失败！", error.message);
              this.$message.error(error.message);
            }
        )
      } else {
        this.$message.warning("请选择节点后再进行操作 ！")
      }
    },
  },
  mounted() {
    this.$bus.$on('node-name', (data) => {
      console.log('EqList - node : ', data);
      let n = data.indexOf('(');
      // console.log('------ n: ',n);
      this.nodeName = data.substring(0, n);
      console.log('------ node: ',this.nodeName);
    })
  }

}
</script>

<style scoped>

</style>